﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TDDConsoleApp
{
    public class WattDBCalculator
    {
        public Decibel WatttoDBm(Watt p)
        {
            Decibel dBm = new Decibel(10 * Math.Log10(1000 * p.Level));
            return dBm;
        }

        public Watt DBmtoWatt(Decibel p)
        {
            Watt watt = new Watt((Math.Pow(10, p.Level / 10)) / 1000);
            return watt;
        }

        public Watt WattAfterGain(Watt watt, Decibel decibel)
        {
            Decibel watttoDB = WatttoDBm(watt);
            Decibel dBSum = new Decibel (watttoDB.Level + decibel.Level);
            return DBmtoWatt(dBSum);
        }

        public Decibel dBLoss(PowerUnit input, PowerUnit output)
        {
            Decibel loss;
            if ((input.Unit == "dBm") && (output.Unit == "dBm"))
                loss = new Decibel(output.Level - input.Level);
            else if ((input.Unit == "Watt(s)") && (output.Unit == "dBm"))
                loss = new Decibel(output.Level - WatttoDBm((Watt)input).Level);
            else if ((input.Unit == "dBm") && (output.Unit == "Watt(s)"))
                loss = new Decibel(WatttoDBm((Watt)output).Level-input.Level);
            else
                loss = new Decibel (WatttoDBm((Watt)output).Level - WatttoDBm((Watt)input).Level);
            return loss;
        }

    }
}
